package com.leyou.item.controller;

import com.leyou.common.enums.ExceptionEnum;
import com.leyou.common.exception.LyException;
import com.leyou.common.utils.BeanHelper;
import com.leyou.item.dto.CategoryDTO;
import com.leyou.item.entity.Category;
import com.leyou.item.service.CategoryService;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    /*
     * @User Administrator
     * @Description //TODO  根据pid查询商品分类列表
     * @Date 10:58 2019/8/9 0009
     * @Param
     * @return
     **/
    @GetMapping("/of/parent")
    public List<CategoryDTO> findCategoryByParentId(@RequestParam Long pid) {
        //调用业务层获取数据结果集
        List<CategoryDTO> categoryDtoList = categoryService.findCategoryByParentId(pid);
        return categoryDtoList;
    }


    /**
     * 根据品牌查询商品类目
     *
     * @param ids
     * @return
     */
    @GetMapping("/of/brand")
    public ResponseEntity<List<CategoryDTO>> findByBrandIds(@RequestParam(value = "ids") List<Long> ids) {
        return ResponseEntity.ok(categoryService.findByBrandIds(ids));
    }

    /**
     * 根据3级分类id，查询1~3级的分类
     * @param id
     * @return
     */
    @GetMapping("/levels")
    public ResponseEntity<List<CategoryDTO>> queryAllByCid3(@RequestParam("id") Long id){
        return ResponseEntity.ok(categoryService.queryAllByCid3(id));
    }
}
